
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import conference.controller.ClientSideTCP;
import conference.controller.ServerSideTCP;
import conference.model.Client;
import conference.model.ConferenceState;
import conference.model.ConferenceStateServerSide;


public class ServerMain {//TODO: finish
	 private static int TCPLISTENPORT = ConferenceState.TCP_PORT; /* port the server listens on */
	 private static ConferenceStateServerSide conference = new ConferenceStateServerSide();
	 
	 public static void main(String args[]){
		 
		 ServerSocket server = null;
		 
		 try {
		     server = new ServerSocket(TCPLISTENPORT); /* start listening on the port */
		 } catch (IOException e) {
		     System.err.println("Could not listen on port: " + TCPLISTENPORT);
		     System.err.println(e);
		     System.exit(1);
		 }
		
		 //add fake users to list.
		 //conference.getList().add(new Client("1.1.1.1","Joon_Fake"));
		 //conference.getList().add(new Client("1.1.1.1","Samuel_Fake"));
		 //conference.getList().add(new Client("1.1.1.1","Romain_Fake"));
		 
		 
		 System.out.println("Server is up and running.");
		 Socket client = null;
		 while(true) {
		     try {
		         client = server.accept();
		     } catch (IOException e) {
		         System.err.println("Accept failed.");
		         System.err.println(e);
		         System.exit(1);
		     }
		     
		     /* start a new thread to handle this client */
		     final Thread t = new Thread(new ServerSideTCP(client, conference));
		     t.start();
		 }
	 }
	
	 
	 
}
